import axios from 'axios'
import qs from 'qs'
import baseURL from '@/ipconfig'
var service = axios.create({
  timeout: 20000,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
})
service.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
service.interceptors.request.use(
  config => {
    if (config.method === 'post') {
      config.data = qs.stringify({
        ...config.data
      })
    }
    // console.log(config.headers)
    return config
  }
)
let $http = null
if (process.env.NODE_ENV == 'production') {
  $http = (params) => {
    params.url = baseURL.voice + params.url
    return service(params)
  }
} else {
  $http = {
    voice(params) {
      params.url = baseURL.voice + params.url
      return service(params)
    }
  }
}
// var serverUrl = process.env.NODE_ENV == 'production' ? 'http://118.31.123.216:8098' : 'http://192.168.11.105:8086'
// var serverUrl = process.env.NODE_ENV == 'production' ? 'http://118.31.123.216:8098' : 'http://118.31.123.216:8098'
// 开启语音播报
// export function voiceBroadcast(params) {
//   console.log(params)
//   return new Promise((resolve, reject) => {
//     axios.post(`${serverUrl}/ogs/voiceReport/send.htm`, { ...params }).then(res => {
//       resolve(res)
//     }).catch((err) => {
//       reject(err)
//     })
//   })
// }
export default $http
